package hhh.app.domain.interactor;

import java.util.HashMap;
import java.util.Map;

import javax.inject.Inject;

import hhh.app.common.Code;
import hhh.app.domain.repository.ProductRepository;
import rx.Observable;

/**
 * Created by hhh on 2016/12/12.
 */
public class GetProducts extends ProductCase {
    private final ProductRepository repository;
    private int start =1;
    private String word ="";
    private int category=-1;
    private String sort="";

    @Inject
    public GetProducts(ProductRepository repository) {
        this.repository = repository;
    }

    public GetProducts setStart(int start) {
        this.start = start;
        return this;
    }

    public GetProducts setWord(String word) {
        this.word = word;
        return this;
    }

    public GetProducts setCategory(int category){
        this.category=category;
        return this;
    }

    @Override
    protected Observable buildProductCaseSubscriber() {
        Map<String,String> map=new HashMap<String, String>();
        map.put("start", String.valueOf(start));
        map.put("limit", String.valueOf(Code.LIMIT));
        if(category!=-1){
            map.put("category", String.valueOf(category));
        }
        if(!sort.equals("")){
            map.put("sort",sort);
        }
        if(!word.equals("")){
            map.put("word",word);
        }
        return repository.products(map);
//        return repository.products(start,category, word,sort);
    }

    public GetProducts setSort(String sort) {
        this.sort=sort;
        return this;
    }
}
